//
//  Platform+Color.swift
//  Charts
//
//  Copyright 2015 Daniel Cohen Gindi & Philipp Jahoda
//  A port of MPAndroidChart for iOS
//  Licensed under Apache License 2.0
//
//  https://github.com/danielgindi/Charts
//

#if canImport(UIKit)
import UIKit

public typealias NSUIColor = UIColor
private func fetchLabelColor() -> UIColor
{
    if #available(iOS 13, tvOS 13, *)
    {
        return .label
    }
    else
    {
        return .black
    }
}
private let labelColor: UIColor = fetchLabelColor()

extension UIColor
{
    static var labelOrBlack: UIColor { labelColor }
    
    static func chart_hexColor(_ hex: String, alpha: CGFloat = 1.0) -> UIColor{
     guard hex.count >= 6 else {
         return UIColor.white
     }
     let hexString = hex.trimmingCharacters(in: .whitespacesAndNewlines)
     let scanner = Scanner(string: hexString)
      
     if hexString.hasPrefix("#") {
         scanner.scanLocation = 1
     }
      
     var color: UInt32 = 0
     scanner.scanHexInt32(&color)
      
     let mask = 0x000000FF
     let r = Int(color >> 16) & mask
     let g = Int(color >> 8) & mask
     let b = Int(color) & mask
      
     let red   = CGFloat(r) / 255.0
     let green = CGFloat(g) / 255.0
     let blue  = CGFloat(b) / 255.0
     return UIColor(red: red, green: green, blue: blue, alpha: alpha)
 }
}
#endif

#if canImport(AppKit) && !targetEnvironment(macCatalyst)

import AppKit

public typealias NSUIColor = NSColor
private func fetchLabelColor() -> NSColor
{
    if #available(macOS 10.14, *)
    {
        return .labelColor
    }
    else
    {
        return .black
    }
}
private let labelColor: NSColor = fetchLabelColor()

extension NSColor
{
    static var labelOrBlack: NSColor { labelColor }
}



#endif
